package com.yungu.swift.report.controller;

import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.admin.AdminReportParam;
import com.yungu.swift.report.entity.ReportOrderScoreDay;
import com.yungu.swift.report.entity.ReportOrderServiceDay;
import com.yungu.swift.report.entity.ReportOrderServiceTotalDay;
import com.yungu.swift.report.service.OrderScoreDayService;
import com.yungu.swift.report.service.OrderServiceDayService;
import com.yungu.swift.report.service.OrderServiceTotalDayService;
import com.yungu.swift.report.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 订单服务控制器
 */
@RestController
@Api(value = "【订单服务】", tags = "订单服务")
public class OrderServiceCtrl {

    @Autowired
    private OrderServiceDayService orderServiceDayService;
    @Autowired
    private OrderScoreDayService orderScoreDayService;
    @Autowired
    private OrderServiceTotalDayService orderServiceTotalDayService;

    @PostMapping("/report/order/service/queryPage")
    @ApiOperation(value = "订单服务数据分页——平均服务分、平均服务时长", httpMethod = "POST")
    public ResponseData<Map<String, Object>> queryPage(@RequestBody AdminReportParam reportParam) {
        switch (reportParam.getTypeReport()) {
            //平均服务评分
            case 3: {
                return orderScoreDayService.queryPage(reportParam);
            }
            //平均服务时长,平均服务里程,接客时长,接客里程
            default: {
                return orderServiceDayService.queryPage(reportParam);
            }
        }
    }

    @PostMapping("/report/order/service/export")
    @ApiOperation(value = "订单服务数据导出", httpMethod = "POST")
    public void export(@RequestBody AdminReportParam reportParam, HttpServletResponse response) throws Exception {
        switch (reportParam.getTypeReport()) {
            //平均服务里程
            case 2: {
                List list = (orderServiceDayService.list(reportParam).getData());
                String templatePath = "/template/order_service_mileage_report.xlsx";
                ExcelUtil.download(reportParam, response, list, ReportOrderServiceDay.class, templatePath, "平均服务里程");

            }
            //平均服务评分
            case 3: {
                List list = (orderScoreDayService.list(reportParam).getData());
                String templatePath = "/template/order_service_score_report.xlsx";
                ExcelUtil.download(reportParam, response, list, ReportOrderScoreDay.class, templatePath, "平均服务评分");

            }
            //接客时长
            case 4: {
                List list = (orderServiceDayService.list(reportParam).getData());
                String templatePath = "/template/order_service_receive_duration_report.xlsx";
                ExcelUtil.download(reportParam, response, list, ReportOrderServiceDay.class, templatePath, "接客时长");

            }
            //接客里程
            case 5: {
                List list = (orderServiceDayService.list(reportParam).getData());
                String templatePath = "/template/order_service_receive_mileage_report.xlsx";
                ExcelUtil.download(reportParam, response, list, ReportOrderServiceDay.class, templatePath, "接客里程");

            }
            //默认：//平均服务时长
            default: {
                List list = (orderServiceDayService.list(reportParam).getData());
                String templatePath = "/template/order_service_duration_report.xlsx";
                ExcelUtil.download(reportParam, response, list, ReportOrderServiceDay.class, templatePath, "平均服务时长");

            }
        }
    }

    @PostMapping("/report/order/service/getTotalInfo")
    @ApiOperation(value = "订单服务总计", httpMethod = "POST")
    public ResponseData<ReportOrderServiceTotalDay> getTotalInfo(@RequestBody AdminReportParam reportParam) {
        return orderServiceTotalDayService.getAvgInfo(reportParam);
    }
}
